package cn.heycm.seata.product.controller;

import cn.heycm.seata.product.dao.ProductRepository;
import cn.heycm.seata.product.dao.entity.Product;
import cn.heycm.seata.product.feign.OrderApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author hey
 * @version 1.0
 * @since 2024/9/10 21:10
 */
@RestController
@RequestMapping("/")
public class ProductController {

    @Autowired
    private OrderApi orderApi;
    @Autowired
    private ProductRepository repository;

    @GetMapping("/ping")
    public String ping() {
        return "product app: pong";
    }

    @GetMapping("/pingOrder")
    public String pingOrder() {
        return orderApi.ping();
    }

    @PostMapping("/update")
    public void update(@RequestParam("productId") Integer productId,
                       @RequestParam("productName") String productName) {
        repository.save(productId, productName);
    }
}
